<template>
  <div class="note">
    <div class="note-list">
      <div
        class="note-item"
        v-for="item in allNoteList"
        :key="item._id"
        @click="routerTo(`/note/detail/${item._id}`)"
      >
        <div class="note-item_header">
          <div class="note-item_header-headImg">
            <van-image round :src="item.author.headImg">
              <template v-slot:loading>
                <van-loading type="spinner" size="20" /> </template
            ></van-image>
          </div>
          <div class="note-item_header-text">
            <div class="note-item_header-text_title">
              {{ item.title }}
            </div>
            <div class="note-item_header-text_username">
              {{ item.author.username }} ·
              {{ daydiff(new Date(item.createTime)) }}
            </div>
          </div>
        </div>
        <div class="note-item_main">
          <div class="note-item_main_content">
            {{ item.content }}
          </div>
          <div class="note-item_main_propImg" v-if="item.imgList[0]">
            <van-image :src="item.imgList[0]" radius="8px" fit="fill">
              <template v-slot:loading>
                <van-loading type="spinner" size="20" /> </template
            ></van-image>
          </div>
        </div>
        <div class="note-item_tail">
          <div class="note-item_tail_icon">
            <div class="note-item_tail_iconItem">
              <van-icon name="good-job-o" />
              <span>&nbsp;&nbsp;{{item.like.length}}</span>
            </div>
            <div class="note-item_tail_iconItem">
              <van-icon name="chat-o" />
              <span>&nbsp;&nbsp;{{item.comments.length}}</span>
            </div>
          </div>
          <div class="note-item_tail_tag">
            <div class="note-item_tail_tagItem">什么什么鸟</div>
            <div class="note-item_tail_tagItem">22222</div>
            <div class="note-item_tail_tagItem">啊实打实的</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { reactive, toRefs } from '@vue/reactivity';
import { onMounted } from '@vue/runtime-core';
import { useRouter } from 'vue-router';
import { daydiff } from '../../../utils/daydiff';

export default {
  props: ['allNoteList'],
  setup(props) {
    const router = useRouter();
    // myUpload.value.chooseFile();
    const routerTo = (url) => {
      router.push({
        path: url,
      });
    };
    const state = reactive({
      left: [],
      right: [],
    });
    onMounted(() => {
      console.log(props.allNoteList[0]);
    });
    return { ...toRefs(state), routerTo, daydiff };
  },
};
</script>
<style lang="less" scoped>
.note {
  width: 95%;
  margin: 0 auto;
  &-list {
    box-sizing: border-box;
    width: 100%;
  }
  &-item {
    text-align: left;
    padding: 10px;
    margin: 15px 0;
    border-radius: 8px;
    box-shadow: 1.333333vw 1.333333vw 2.666667vw #eeeeee,
      -1.333333vw -1.333333vw 2.666667vw #eeeeee;
    &_header {
      font-size: 15px;
      line-height: 30px;
      height: 50px;
      display: flex;
      &-headImg {
        height: 36px;
        width: 36px;
        padding: 5px;
        display: flex;
        align-items: center;
        justify-content: center;
        ::v-deep(.van-image) {
          height: 36px;
          width: 36px;
        }
      }
      &-text {
        margin-left: 5px;
        &_title {
          height: 22px;
          font-size: 16px;
          font-weight: 500;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: pre;
          line-height: 28px;
          margin-bottom: 2px;
        }
        &_username {
          height: 20px;
          line-height: 20px;
          color: rgb(133, 133, 133);
          font-size: 11px;
        }
      }
    }
    &_main {
      display: flex;
      justify-content: space-between;
      &_content {
        flex: 1;
        height: 80px;
        padding: 0 5px;
        font-size: 14px;
        line-height: 20px;
        -webkit-line-clamp: 4;
        font-family: '微软雅黑';
        width: 100%;
        line-clamp: 4;
        overflow: hidden;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        margin-bottom: 8px;
        text-indent: 0.8cm;
        letter-spacing: 1px;
        word-break: break-all;
        color: rgb(126, 123, 123);
      }

      &_propImg {
        margin-left: 10px;
        ::v-deep(.van-image) {
          height: 80px;
          width: 120px;
        }
      }
    }
    &_tail {
      display: flex;
      align-items: center;
      justify-content: space-between;
      &_icon {
        display: flex;
        padding: 2px 0 3px 5px;
        &Item {
          margin-right: 9px;
          font-size: 14px;
        }
      }
      &_tag {
        display: flex;
        align-items: center;
        font-size: 11px;
        &Item {
          display: flex;
          text-align: center;
          align-items: center;
          justify-content: center;
          margin: 3px;
          height: 14px;
          background: #75afe9;
          box-sizing: border-box;
          padding: 8px;
          border-radius: 5px;
        }
      }
    }
  }
}
</style>
